package com.ktwlsoft.fundmanage.controller;

import com.ktwlsoft.fundmanage.domain.business.FundOutService;
import com.ktwlsoft.fundmanage.domain.entity.DataDictionary;
import com.ktwlsoft.fundmanage.domain.entity.FundInRecord;
import com.ktwlsoft.fundmanage.domain.entity.TransferApply;
import com.ktwlsoft.fundmanage.payload.fundOut.FindTransferApplyPageRequest;
import com.ktwlsoft.fundmanage.payload.fundOut.RefundMoneyOrderAdministrationPageRequest;
import com.ktwlsoft.fundmanage.service.DataDictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 涵盖所有资金流出相关的查询api
 * @author LanJian
 *
 */
@Api(description = "出账、退款相关查询，作者：朱和")
@RestController
@RequestMapping("/fundout")
public class FundOutController {

    /**数据字典*/
    private final DataDictionaryService dictionaryService;

    /**资金流出相关*/
    private final FundOutService fundOutService;

    public FundOutController(DataDictionaryService dictionaryService, FundOutService fundOutService){
        this.dictionaryService = dictionaryService;
        this.fundOutService = fundOutService;
    }

    /**
      * 数据字典-新增或修改 on 2019/9/4 16:31
      *
      * @param dataDictionary dataDictionary
      * @return ResponseEntity<?>
      */
    @ApiOperation(value = "数据字典-新增或修改", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping(value = "dataDictionarySaveOrUpdate")
    public ResponseEntity<?> dataDictionarySaveOrUpdate(@RequestBody DataDictionary dataDictionary) {
        return ResponseEntity.ok(dictionaryService.save(dataDictionary));
    }

    /**
     * 数据字典-物理删除 on 2019/9/4 16:31
     *
     * @param dataDictionary dataDictionary
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "数据字典-物理删除", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping(value = "delete")
    public ResponseEntity<?> delete(@RequestBody DataDictionary dataDictionary) {
        return ResponseEntity.ok(dictionaryService.delete(dataDictionary));
    }

    /**
     * 数据字典-启用禁用 on 2019/9/4 16:31
     *
     * @param id id
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "数据字典-启用禁用", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "updateState")
    public ResponseEntity<?> updateState(@ApiParam(name = "id", value = "字典id") @RequestParam(defaultValue = "", required = true)Long id) {
        return ResponseEntity.ok(dictionaryService.updateState(id));
    }

    /**
     * 数据字典-分页 on 2019/9/4 16:31
     *
     * @param dataDictionary dataDictionary
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "数据字典-分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "findPage")
    public ResponseEntity<?> findPage(@RequestParam(defaultValue = "1") int pn,
                                      @RequestParam(defaultValue = "30") int pageSize,
                                      DataDictionary dataDictionary) {
        return ResponseEntity.ok(dictionaryService.findPage(pn,pageSize,dataDictionary));
    }

    /**
     * 数据字典-根据id查询数据 on 2019/9/4 16:31
     *
     * @param id id
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "数据字典-根据id查询数据", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "getByid")
    public ResponseEntity<?> getByid(@ApiParam(name = "id", value = "字典id") @RequestParam(defaultValue = "", required = true)Long id) {
        return ResponseEntity.ok(dictionaryService.getByid(id));
    }

    /**
     * 数据字典-根据key查询数据 on 2019/9/4 16:31
     *
     * @param key key
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "数据字典-根据key查询数据", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "getByKey")
    public ResponseEntity<?> getByKey(@ApiParam(name = "key", value = "字典key") @RequestParam(defaultValue = "", required = true)String key) {
        return ResponseEntity.ok(dictionaryService.getByKey(key));
    }

    /**
     * 数据字典-根据父id查询数据 on 2019/9/4 16:31
     *
     * @param parentId parentId
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "数据字典-根据父id查询数据", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "getByParentId")
    public ResponseEntity<?> getByParentId(@ApiParam(name = "parentId", value = "父id") @RequestParam(defaultValue = "", required = true)Long parentId) {
        return ResponseEntity.ok(dictionaryService.getByParentId(parentId));
    }

    /**
     * 划款单列表 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "划款单列表", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("findTransferApplyPage")
    public ResponseEntity<?> findTransferApplyPage(@RequestParam(defaultValue = "1") int pn,
                                                   @RequestParam(defaultValue = "30") int pageSize,
                                                   FindTransferApplyPageRequest findTransferApplyPageRequest){
        return ResponseEntity.ok(fundOutService.findTransferApplyPage(pn,pageSize,findTransferApplyPageRequest));
    }

    /**
     * 划款单管理-审核列表 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "划款单管理-审核列表", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("findTransferApplyToExaminePage")
    public ResponseEntity<?> findTransferApplyToExaminePage(@RequestParam(defaultValue = "1") int pn,
                                                   @RequestParam(defaultValue = "30") int pageSize,
                                                   FindTransferApplyPageRequest findTransferApplyPageRequest){
        return ResponseEntity.ok(fundOutService.findTransferApplyToExaminePage(pn,pageSize,findTransferApplyPageRequest));
    }

    /**
     * 退回处理分页 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "退回处理分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("returnHandlePage")
    public ResponseEntity<?> returnHandlePage(@RequestParam(defaultValue = "1") int pn,
                                              @RequestParam(defaultValue = "30") int pageSize,
                                              @ApiParam(name = "tsCode", value = "交易编号") @RequestParam(defaultValue = "", required = false)Long tsCode,
                                              @ApiParam(name = "forceCancel", value = "是否强制撤销") @RequestParam(defaultValue = "", required = false)Boolean forceCancel,
                                              @ApiParam(name = "state", value = "划款单状态类型") @RequestParam(defaultValue = "", required = false)TransferApply.State state){
        return ResponseEntity.ok(fundOutService.returnHandlePage(pn,pageSize,tsCode,forceCancel,state));
    }

    /**
     * 资金缴款-退回处理分页 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "资金缴款-退回处理分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("fundInReturnHandlePage")
    public ResponseEntity<?> fundInReturnHandlePage(@RequestParam(defaultValue = "1") int pn,
                                                    @RequestParam(defaultValue = "30") int pageSize,
                                                    @ApiParam(name = "tsCode", value = "交易编号") @RequestParam(defaultValue = "", required = false)Long tsCode,
                                                    @ApiParam(name = "state", value = "入账状态") @RequestParam(defaultValue = "", required = false)FundInRecord.State state,
                                                    @ApiParam(name = "isReturn", value = "是否曾退回") @RequestParam(defaultValue = "", required = false)Boolean isReturn){
        return ResponseEntity.ok(fundOutService.fundInReturnHandlePage(pn,pageSize,tsCode,state,isReturn));
    }

    /**
     * 划款单详情 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "划款单详情", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("getFindTransferApplyDetails")
    public ResponseEntity<?> getFindTransferApplyDetails(@ApiParam(name = "id", value = "主键") @RequestParam(defaultValue = "", required = true)Long id){
        return ResponseEntity.ok(fundOutService.getFindTransferApplyDetails(id));
    }

    /**
     * 资金划款-分页 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "资金划款-分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("capitalDrawMoney")
    public ResponseEntity<?> capitalDrawMoney(@RequestParam(defaultValue = "1") int pn,
                                                   @RequestParam(defaultValue = "30") int pageSize,
                                                   FindTransferApplyPageRequest findTransferApplyPageRequest){
        return ResponseEntity.ok(fundOutService.capitalDrawMoney(pn,pageSize,findTransferApplyPageRequest));
    }

    /**
     * 退款管理-分页 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "退款管理-分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("refundAdministration")
    public ResponseEntity<?> refundAdministration(@RequestParam(defaultValue = "1") int pn,
                                                  @RequestParam(defaultValue = "30") int pageSize,
                                                  @ApiParam(name = "keyWords", value = "关键字") @RequestParam(defaultValue = "", required = false)String keyWords){
        return ResponseEntity.ok(fundOutService.refundAdministration(pn,pageSize,keyWords));
    }

    /**
     * 退款划款单管理-分页 on 2019/8/15 18:35
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "退款划款单管理-分页", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping("refundMoneyOrderAdministrationPage")
    public ResponseEntity<?> refundMoneyOrderAdministrationPage(@RequestParam(defaultValue = "1") int pn,
                                                                @RequestParam(defaultValue = "30") int pageSize,
                                                                RefundMoneyOrderAdministrationPageRequest request){
        return ResponseEntity.ok(fundOutService.refundMoneyOrderAdministrationPage(pn,pageSize,request));
    }
}
